export const getParam = (variable: string) => {
    var query = window.location.search.substring(1)
    var vars = query.split('&')
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split('=')
        if (pair[0] == variable) {
            return pair[1]
        }
    }
    return ''
}

export const getUrlParams = () => {
    return window.location.search.substring(1)
}

export const formatDate = (date: string) => {
    const nDate = new Date(date)
    const year = nDate.getFullYear()
    const month = (nDate.getMonth() + 1).toString().padStart(2, '0')
    const day = nDate.getDate().toString().padStart(2, '0')
    const hour = nDate.getHours().toString().padStart(2, '0')
    const minute = nDate.getMinutes().toString().padStart(2, '0')
    const ss = nDate.getSeconds().toString().padStart(2, '0')
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + ss
}

export const formatDateHms = (date: string) => {
    const nDate = new Date(date)
    const hour = nDate.getHours().toString().padStart(2, '0')
    const minute = nDate.getMinutes().toString().padStart(2, '0')
    const ss = nDate.getSeconds().toString().padStart(2, '0')
    return hour + ':' + minute + ':' + ss
}

export const getNowTime = () => {
    const nDate = new Date()
    const year = nDate.getFullYear()
    const month = (nDate.getMonth() + 1).toString().padStart(2, '0')
    const day = nDate.getDate().toString().padStart(2, '0')
    const hour = nDate.getHours().toString().padStart(2, '0')
    const minute = nDate.getMinutes().toString().padStart(2, '0')
    const ss = nDate.getSeconds().toString().padStart(2, '0')
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + ss
}

export const getNowTimeText = () => {
    const nDate = new Date()
    const hour = nDate.getHours().toString().padStart(2, '0')
    const minute = nDate.getMinutes().toString().padStart(2, '0')
    const ss = nDate.getSeconds().toString().padStart(2, '0')
    return hour + ':' + minute + ':' + ss
}
